
Ext.onReady(function(){
	new MyApp.view.view();
	var un=document.getElementById('usernamediv').innerHTML;	
	Ext.getCmp('username').setValue(un);
});

//这句话要替换view里面那句html
//html: '您的用户名是：'+document.getElementById('usernamediv').innerHTML+'<br/>\r\n您的密码是：'+document.getElementById('passworddiv').innerHTML+'<br/>\r\n您的用户类型是：'+document.getElementById('userclassdiv').innerHTML+'',

Ext.define('MyApp.view.view', {
    extend: 'Ext.panel.Panel',

    frame: true,
    height: 555,
    id: 'view',
    renderTo: 'container_down',
    width: 1366,
    layout: {
        type: 'border'
    },
    header: false,
    title: 'My Panel',

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [
                {
                    xtype: 'panel',
                    region: 'west',
                    frame: true,
                    width: 317,
                    title: '功能列表',
                    items: [
                        {
                            xtype: 'button',
                            handler: function(button, event) {
                                Ext.getCmp('gerenxinxi').setVisible(true);
                                Ext.getCmp('gerenxinxihead').setVisible(true);
                                Ext.getCmp('tabPanel').setActiveTab(0);
                            },
                            height: 26,
                            width: 318,
                            text: '查看管理员信息'
                        },
                        {
                            xtype: 'button',
                            handler: function(button, event) {
                                Ext.getCmp('xiugaigerenxinxi').setVisible(true);
                                Ext.getCmp('xiugaigerenxinxihead').setVisible(true);
                                Ext.getCmp('tabPanel').setActiveTab(1);
                            },
                            height: 26,
                            width: 318,
                            text: '修改管理员信息'
                        },
                        {
                            xtype: 'button',
                            handler: function(button, event) {
                                Ext.getCmp('tianjiayonghu').setVisible(true);
                                Ext.getCmp('tianjiayonghuhead').setVisible(true);
                                Ext.getCmp('tabPanel').setActiveTab(2);
                            },
                            height: 26,
                            width: 318,
                            text: '添加用户'
                        },
                        {
                            xtype: 'button',
                            handler: function(button, event) {
                                Ext.getCmp('yonghuliebiao').setVisible(true);
                                Ext.getCmp('yonghuliebiaohead').setVisible(true);
                                Ext.getCmp('tabPanel').setActiveTab(3);
                            },
                            height: 26,
                            width: 318,
                            text: '用户列表'
                        },
                        {
                            xtype: 'button',
                            handler: function(button, event) {
                                Ext.getCmp('xiugaiyonghuxinxi').setVisible(true);
                                Ext.getCmp('xiugaiyonghuxinxihead').setVisible(true);
                                Ext.getCmp('tabPanel').setActiveTab(4);
                            },
                            height: 26,
                            width: 318,
                            text: '修改用户信息'
                        }
                    ]
                },
                {
                    xtype: 'tabpanel',
                    region: 'center',
                    id: 'tabPanel',
                    activeTab: 0,
                    items: [
                        {
                            xtype: 'panel',
                            frame: true,
							html: '您的用户名是：'+document.getElementById('usernamediv').innerHTML+'<br/>\r\n您的密码是：'+document.getElementById('passworddiv').innerHTML+'<br/>\r\n您的用户类型是：'+document.getElementById('userclassdiv').innerHTML+'',
                            id: 'gerenxinxi',
                            width: 1037,
                            title: '个人信息',
                            tabConfig: {
                                xtype: 'tab',
                                id: 'gerenxinxihead'
                            }
                        },
                        {
                            xtype: 'panel',
                            frame: true,
                            id: 'xiugaigerenxinxi',
                            layout: {
                                type: 'absolute'
                            },
                            title: '修改个人信息',
                            tabConfig: {
                                xtype: 'tab',
                                id: 'xiugaigerenxinxihead'
                            },
                            items: [
                                {
                                    xtype: 'form',
                                    x: -8,
                                    y: -9,
                                    border: false,
                                    frame: true,
                                    height: 530,
                                    id: 'changeForm',
                                    width: 1035,
                                    layout: {
                                        type: 'absolute'
                                    },
                                    bodyPadding: 10,
                                    header: false,
                                    title: 'My Form',
                                    items: [
                                        {
                                            xtype: 'button',
                                            handler: function(button, event) {
                                                Ext.getCmp('password').setValue(''); 
                                                Ext.getCmp('password2').setValue(''); 
                                            },
                                            x: 550,
                                            y: 280,
                                            height: 40,
                                            width: 140,
                                            text: '重置'
                                        },
                                        {
                                            xtype: 'button',
                                            handler: function(button, event) {
                                                if(Ext.getCmp('password').getValue()!=Ext.getCmp('password2').getValue()){
                                                    alert('两次输入的密码不一致！');
                                                }
                                                else{
                                                    Ext.Ajax.request({
                                                        url: './changeUserAction',
                                                        params:{
                                                            username:Ext.getCmp('username').getValue(),
                                                            password:Ext.getCmp('password').getValue()
                                                        },  
                                                        success: function(response, opts) {
                                                            document.getElementById('usernamediv').innerHTML=Ext.getCmp('username').getValue();
                                                            document.getElementById('passworddiv').innerHTML=Ext.getCmp('password').getValue();  
                                                            Ext.getCmp('gerenxinxi').body.update('您的用户名是：'+document.getElementById('usernamediv').innerHTML+'<br/>\r\n您的密码是：'+document.getElementById('passworddiv').innerHTML+'<br/>\r\n您的用户类型是：'+document.getElementById('userclassdiv').innerHTML+'');
                                                            alert('修改成功！');
                                                            Ext.getCmp('gerenxinxi').setVisible(true);
                                                            Ext.getCmp('gerenxinxihead').setVisible(true);
                                                            Ext.getCmp('tabPanel').setActiveTab(0);
                                                            Ext.getCmp('password').setValue(''); 
                                                            Ext.getCmp('password2').setValue('');        
                                                        }
                                                    });
                                                }
                                            },
                                            x: 350,
                                            y: 280,
                                            height: 40,
                                            width: 140,
                                            text: '确认'
                                        },
                                        {
                                            xtype: 'textfield',
                                            x: 330,
                                            y: 220,
                                            height: 32,
                                            id: 'password2',
                                            width: 380,
                                            fieldLabel: '请重复密码',
                                            labelWidth: 130,
                                            name: 'password2',
                                            inputType: 'password'
                                        },
                                        {
                                            xtype: 'textfield',
                                            x: 330,
                                            y: 170,
                                            height: 32,
                                            id: 'password',
                                            width: 380,
                                            fieldLabel: '请输入修改后的密码',
                                            labelWidth: 130,
                                            name: 'password',
                                            inputType: 'password'
                                        },
                                        {
                                            xtype: 'textfield',
                                            x: 330,
                                            y: 120,
                                            height: 32,
                                            id: 'username',
                                            width: 380,
                                            fieldLabel: '用户名',
                                            labelWidth: 130,
                                            name: 'username',
                                            readOnly: true
                                        }
                                    ]
                                }
                            ]
                        },
                        {
                            xtype: 'panel',
                            frame: true,
                            id: 'tianjiayonghu',
                            width: 1037,
                            layout: {
                                type: 'absolute'
                            },
                            title: '添加用户',
                            tabConfig: {
                                xtype: 'tab',
                                id: 'tianjiayonghuhead'
                            },
                            items: [
                                {
                                    xtype: 'textfield',
                                    x: 330,
                                    y: 120,
                                    height: 32,
                                    id: 'newusername',
                                    width: 380,
                                    fieldLabel: '请输入新用户名',
                                    labelWidth: 130
                                },
                                {
                                    xtype: 'textfield',
                                    x: 330,
                                    y: 170,
                                    height: 32,
                                    id: 'newpassword',
                                    width: 380,
                                    fieldLabel: '请输入密码',
                                    labelWidth: 130,
                                    inputType: 'password'
                                },
                                {
                                    xtype: 'textfield',
                                    x: 330,
                                    y: 220,
                                    height: 32,
                                    id: 'newpassword2',
                                    width: 380,
                                    fieldLabel: '请重复密码',
                                    labelWidth: 130,
                                    inputType: 'password'
                                },
                                {
                                    xtype: 'button',
                                    handler: function(button, event) {
                                        if(Ext.getCmp('newpassword').getValue()!=Ext.getCmp('newpassword2').getValue()){
                                            alert('两次输入的密码不一致！');
                                        }
                                        else{
                                            Ext.Ajax.request({
                                                url: './registAction',
                                                params:{
                                                    username:Ext.getCmp('newusername').getValue(),
                                                    password:Ext.getCmp('newpassword').getValue(),
                                                    password2:Ext.getCmp('newpassword').getValue(),
                                                    userclass:'用户'
                                                },  
                                                success: function(response, opts) {
                                                    alert('添加新用户成功！');
                                                    Ext.getCmp('newusername').setValue('');
                                                    Ext.getCmp('newpassword').setValue(''); 
                                                    Ext.getCmp('newpassword2').setValue('');        
                                                },
                                                failure: function(response, opts) {
                                                    alert('用户名已存在！');
                                                }
                                            });
                                        }
                                    },
                                    x: 350,
                                    y: 280,
                                    height: 40,
                                    width: 140,
                                    text: '确认'
                                },
                                {
                                    xtype: 'button',
                                    handler: function(button, event) {
                                        Ext.getCmp('newusername').setValue(''); 
                                        Ext.getCmp('newpassword').setValue(''); 
                                        Ext.getCmp('newpassword2').setValue(''); 
                                    },
                                    x: 550,
                                    y: 280,
                                    height: 40,
                                    width: 140,
                                    text: '重置'
                                }
                            ]
                        },
                        {
                            xtype: 'panel',
                            frame: true,
                            html: '<iframe src="./listUserAction" height="100%" width="100%" frameborder="0"></iframe>',
                            id: 'yonghuliebiao',
                            title: '用户列表',
                            tabConfig: {
                                xtype: 'tab',
                                id: 'yonghuliebiaohead'
                            }
                        },
                        {
                            xtype: 'panel',
                            frame: true,
                            id: 'xiugaiyonghuxinxi',
                            layout: {
                                type: 'absolute'
                            },
                            title: '修改用户信息',
                            tabConfig: {
                                xtype: 'tab',
                                id: 'xiugaiyonghuxinxihead'
                            },
                            items: [
                                {
                                    xtype: 'textfield',
                                    x: 330,
                                    y: 120,
                                    height: 32,
                                    id: 'changeusername',
                                    width: 380,
                                    fieldLabel: '请输入欲修改的用户名',
                                    labelWidth: 130
                                },
                                {
                                    xtype: 'textfield',
                                    x: 330,
                                    y: 190,
                                    height: 32,
                                    id: 'changepassword',
                                    width: 380,
                                    fieldLabel: '请输入修改后的密码',
                                    labelWidth: 130
                                },
                                {
                                    xtype: 'button',
                                    handler: function(button, event) {
                                        Ext.Ajax.request({
                                            url: './changeUserAction',
                                            params:{
                                                username:Ext.getCmp('changeusername').getValue(),
                                                password:Ext.getCmp('changepassword').getValue()
                                            },  
                                            success: function(response, opts) {
                                                alert('修改用户信息成功！');
                                                Ext.getCmp('changeusername').setValue('');
                                                Ext.getCmp('changepassword').setValue('');    
                                            },
                                            failure: function(response, opts) {
                                                alert('用户不存在！');
                                            }
                                        });
                                    },
                                    x: 350,
                                    y: 260,
                                    height: 40,
                                    width: 140,
                                    text: '确认'
                                },
                                {
                                    xtype: 'button',
                                    handler: function(button, event) {
                                        Ext.getCmp('changeusername').setValue(''); 
                                        Ext.getCmp('changepassword').setValue(''); 
                                    },
                                    x: 550,
                                    y: 260,
                                    height: 40,
                                    width: 140,
                                    text: '重置'
                                }
                            ]
                        }
                    ]
                }
            ]
        });

        me.callParent(arguments);
    }

});